// pages/more/more.js
Page({
  /**
   * 页面的初始数据
   */
  data: {
     
    userInfo: {},
    hasUserInfo: false,
    canIUse: wx.canIUse('button.open-type.getUserInfo'),
    canIUseGetUserProfile: false,
    canIUseOpenData: wx.canIUse('open-data.type.userAvatarUrl') && wx.canIUse('open-data.type.userNickName'), // 如需尝试获取用户信息可改为false
    /** 
        * 页面配置 
        */  
       winWidth: 0,  
       winHeight: 0,  
       // tab切换  
       currentTab: 0, 
    
       Activity :[//  活动日程
        {
          act_id:"1",
          act_start_time: "2021-07-09 10:30:54",
          act_end_time: "2021-07-09 11:31:03",
          act_name:"这里是某活动",
          room_name:"某区-xxx-x排x列",
        },
        {
          act_id:"2",
          act_start_time: "3000-6-05 10:30:54",
          act_end_time: "2021-07-09 11:31:03",
          act_name:"这里是某活动",
          room_name:"某区-xxx-x排x列",
        },
        {
          act_id:"3",
          act_start_time: "2019-6-05 10:30:54",
          act_end_time: "2021-07-09 11:31:03",
          act_name:"这里是某活动",
          room_name:"某区-xxx-x排x列",
        },
        {
          act_id:"4",
          act_start_time: "2010-6-05 10:30:54",
          act_end_time: "2021-07-09 11:31:03",
          act_name:"这里是某活动",
          room_name:"某区-xxx-x排x列",
        },
        {
          act_id:"5",
          act_start_time: "2000-6-05 10:30:54",
          act_end_time: "2021-07-09 11:31:03",
          act_name:"这里是某活动",
          room_name:"某区-xxx-x排x列",
        },
        {
          act_id:"6",
          act_start_time: "1999-6-05 10:30:54",
          act_end_time: "2021-07-09 11:31:03",
          act_name:"这里是某活动",
          room_name:"某区-xxx-x排x列",
        },
        
      ],
      History:[//历史选座
        {
          act_id:"1",
          act_start_time: "2021-07-09 10:30:54",
          act_end_time: "2021-07-09 11:31:03",
          act_name:"这里是某活动",
          room_name:"某区-xxx-x排x列",
        },
  
      ],
      Default_record:[//违约记录
        {
          act_id:"1",
          act_start_time: "2021-07-09 10:30:54",
          act_end_time: "2021-07-09 11:31:03",
          act_name:"这里是某活动",
          room_name:"某区-xxx-x排x列",
        },
      ],
      // 顶部菜单切换
      navbar: ['活动日程', '历史记录', "违约记录"],
      // 默认选中菜单
      currentTab: 0,
      index: 0,
      pick_name: "",
      
   
    },
 
  
    
   
    onLoad() {
      if (wx.getUserProfile) {
        this.setData({
          canIUseGetUserProfile: true
        })
      }
      var that = this;  
      /** 
       * 获取系统信息 
       */  
      wx.getSystemInfo( {  
        success:(res)=> {  
          that.setData( {  
            winWidth: res.windowWidth,  
            winHeight:this.data.Activity.length*160,
          });  
        }  
      });
       
      
    },
    getUserProfile(e) {
      // 推荐使用wx.getUserProfile获取用户信息，开发者每次通过该接口获取用户个人信息均需用户确认，开发者妥善保管用户快速填写的头像昵称，避免重复弹窗
      wx.getUserProfile({
        desc: '展示用户信息', // 声明获取用户个人信息后的用途，后续会展示在弹窗中，请谨慎填写
        success: (res) => {
          console.log(res)
          this.setData({
            userInfo: res.userInfo,
            hasUserInfo: true
          })
        }
      })
    },
    getUserInfo(e) {
      // 不推荐使用getUserInfo获取用户信息，预计自2021年4月13日起，getUserInfo将不再弹出弹窗，并直接返回匿名的用户个人信息
      console.log(e)
      this.setData({
        userInfo: e.detail.userInfo,
        hasUserInfo: true
      })
    },

  cancel_seat:function(){//取消选座
    wx.showToast({
      title: '退选成功',//提示文字
      duration:2000,//显示时长
      mask:true,//是否显示透明蒙层，防止触摸穿透，默认：false  
      icon:'success', //图标，支持"success"、"loading"  
      success:function(){ },//接口调用成功
      fail: function () { },  //接口调用失败的回调函数  
      complete: function () { } //接口调用结束的回调函数  
   })
  },

  setting:function(){//设置按钮
    wx.navigateTo({
      url: '/pages/setting/setting',
    })
  },
  bindChange: function( e ) {  
    var that = this;  
    that.setData( { currentTab: e.detail.current });  
  }, 

  /** 
   * 点击tab切换 
   */  
  swichNav: function( e ) {  
  
    var that = this;  
  
    if( this.data.currentTab === e.target.dataset.current ) {  
      return false;  
    } else {  
      that.setData( {  
        currentTab: e.target.dataset.current  
      })  
    }  
  }, 



 /**
   *特殊写法:比较数组date日期
   */
  compare: function(property) {
    return function(a, b) {
      var value1 = Date.parse(a[property]);
      var value2 = Date.parse(b[property]);
      return value1 - value2;
    }
  },

  TimeSort:function(e){//按活动时间排序
     //property 根据什么排序
    var property = e.currentTarget.dataset.property;
    console.log(property);
    var self = this;
    var Activity = self.data.Activity;
    self.setData({
      Activity: Activity.sort(self.compare(property))
    })
    console.log(Activity);
  },
  
  shensu:function(e){//申诉
    var id = e.currentTarget.dataset.id;
    console.log(id);
    wx.navigateTo({
      url: '/pages/complain/complain?id='+id,  //传参
    })
    }



  
})